import 'dart:math';

extension ListExtension<T> on List<T> {
  T? firstWhereOrNull(bool Function(T) test) {
    for (final element in this) {
      if (test(element)) return element;
    }
    return null;
  }

  // 取前N个值
  List<T> takeFirstN(int n) {
    assert(n >= 0, 'n must be non-negative');
    if (isEmpty || n == 0) return [];
    return sublist(0, min(n, length));
  }
}
